
def createProjectLocation

task( 'create-web-project' : 'Create a new web project structure' ) {
	createProjectMain()
	createWarBuildGroovy()
}

task( 'create-project' : 'Create a new project structure' ) {
	createProjectMain()
	createJarBuildGroovy()
}

task( 'createProjectMain' : '' ) {
	Ant.input( message: "Please enter project name and press enter:", addProperty: 'create-project.name' )
	
	def projectName = Ant.antProject.properties."create-project.name"
	
	def projectLocation = new File( "projects/${projectName}" )
	
	if (projectLocation.exists()) {
		println("[ERROR] The project location ${projectLocation.absolutePath} already exists")
	} else {
		projectLocation.mkdirs()
		createProjectLocation = projectLocation.absolutePath
		createProjectStructure()
	}
}

task( 'createProjectStructure' : '' ) {
	def project = createProjectLocation
	
	if (!project) {
		println( "[ERROR] Project location not set?!" )
		return
	}
	
	def projectLocation = new File( project )
	
	if (!projectLocation.exists() || !projectLocation.directory) {
		println("[ERROR] Project location ${projectLocation.absolutePath} doesn't exist or is not a directory")
	} else {
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/main/java" )
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/main/groovy" )
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/main/resources" )
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/test/java" )
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/test/groovy" )
		Ant.mkdir( dir: "${projectLocation.absolutePath}/src/test/resources" )		
	}
}

task( 'createJarBuildGroovy' : '' ) {
	def build_groovy_file = new File( "${createProjectLocation}/Build.groovy" )
	
	build_groovy_file << """// ${new Date()}
// Generated Build.groovy file. Edit this file to set your project preferences.

libs = [

]

test_libs = [
	"junit-3.8.2"
]

packaging = "jar"

deps = [

]
		
"""
}

task( 'createWarBuildGroovy' : '' ) {
	def build_groovy_file = new File( "${createProjectLocation}/Build.groovy" )
	
	build_groovy_file << """// ${new Date()}
// Generated Build.groovy file. Edit this file to set your project preferences.

libs = [

]

test_libs = [
	"junit-3.8.2"
]

packaging = "war"

deps = [

]
		
"""
}